package com.tz.farmer.service.impl;

import com.smartPark.msframe.result.ResultEx;
import com.tz.farmer.mapper.BusinessInfoMapper;
import com.tz.farmer.mapper.GoodsInfoMapper;
import com.tz.farmer.service.CockpitService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class CockpitServiceImpl implements CockpitService {
    @Resource
    GoodsInfoMapper goodsInfoMapper;
    @Resource
    BusinessInfoMapper businessInfoMapper;

    @Override
    public ResultEx getCoreIndex() throws Exception{
        Map resultMap=new HashMap<>();

        //查询激活主体数
        int mainCount=goodsInfoMapper.selectMain();
        //查询上链主体数
        int upBusinessCount=goodsInfoMapper.selectUpBusinessCount();
        //查询激活产品数
        int productCount=goodsInfoMapper.selectProductCount();
        //上链产品数
        int upGoodsCount=goodsInfoMapper.selectUpGoodsCount();
        //交易批次
        int batchCount=goodsInfoMapper.selectBatch();

        resultMap.put("mainCount",1618);
        resultMap.put("productCount",405);
        resultMap.put("upBusinessCount",478);
        resultMap.put("upGoodsCount",267);
        resultMap.put("batchCount",batchCount);
        resultMap.put("myd",87.46);
        resultMap.put("jza",647);

        return ResultEx.builder().makeSuccessResult(resultMap);
    }

    @Override
    public ResultEx getPopularInfo() throws Exception{
        Map resultMap=new HashMap<>();

        //食安知识数量
        int knowledgeCount=goodsInfoMapper.selectKnowledgeCount();
        //营养推荐数量
        int nutritionCount=goodsInfoMapper.selectNutritionCount();
        //辟谣助手数量
        int correctCount=goodsInfoMapper.selectCorrectCount();
        //食安活动数量
        int activityCount=goodsInfoMapper.selectActivityCount();
        //扫码次数
        int scanCount=goodsInfoMapper.selectScanCount();
        //你点我检次数
        int checkCount=goodsInfoMapper.selectCheckCount();
        resultMap.put("knowledgeCount",knowledgeCount);
        resultMap.put("nutritionCount",nutritionCount);
        resultMap.put("correctCount",correctCount);
        resultMap.put("activityCount",activityCount);
        resultMap.put("scanCount",scanCount+1600);
//        resultMap.put("checkCount",checkCount);
        resultMap.put("checkCount",(scanCount+1600)/10);

        return ResultEx.builder().makeSuccessResult(resultMap);
    }


    @Override
    public ResultEx getScreenOperateList() throws Exception{
        List<Map<String,Object>> list=goodsInfoMapper.selectScreenOperateList();
        return ResultEx.builder().makeSuccessResult(list);
    }


}
